1. Field of the Invention
This invention relates to a variable length code processor and image processor, and more particularly for example to a variable length code processor and image processor suitable for encoding and decoding of images, or variable length encoding and decoding of sound.
2. Description of the Related Art
When, for example, MPEG (Moving Experts Picture Group) coding is performed, image data is converted into DCT coefficients by DCT (Direct Cosine Transform), and after these DCT coefficients are quantized, they are variable length coded. In this variable length coding, a variable length code corresponding to a run length and level of a quantized DCT coefficient is output.
When MPEG decoding is performed, the aforesaid variable length code is variable length decoded, and converted into the run length and level of the quantized DCT coefficient. A quantized DCT coefficient is generated based on this run length and level, and the image is decoded by applying reverse quantization and reverse DCT.
FIG. 16 shows the layout of a conventional VLC (variable length coder) provided in an image encoder which performs this type of MPEG coding.
A coding table storage unit 61 stores coding tables containing variable length codes associated with combinations of run length and level. Run lengths and levels of quantized DCT coefficients are supplied to this unit. The coding table storage unit 61 outputs variable length codes corresponding to run length and level, using run length and level as input.
In other words, the coding table storage unit 61 reads a variable length code stored in an address which is a run length and level combination input to the unit. This variable length code is supplied to a barrel shifter 62.
In addition to the variable length code, the length of this code is also contained in the coding table. The length of the variable length code supplied to the barrel shifter 62 is read from the coding table storage unit 61, and supplied to a controller 64.
Herein, the word width of the variable length codes stored in the coding table is, for example, identical to the maximum length L of the variable length codes. Variable length codes shorter than L are, for example, lengthened to L bits by placing 0B (where B indicates a binary number) in the upper bits. Therefore when the length of the variable length code corresponding to a given run length and level combination is i (&lt;=L), the output of the coding table storage unit 61 has L-i .times.0B added to the upper bits of the variable length code. Therefore to output continuous variable length code sequences as the coding result, the L-i.times.0B added to the upper bits must be removed from the output of the coding table storage unit 61.
The output of the coding table storage unit 61 is bit-shifted in the barrel shifter 62. As a result, the MSB (uppermost bit) of the variable length code contained in the present output of the coding table storage unit 61 is moved to a position one bit below the lowermost bit (LSB) of the variable length code contained in the output of the coding table storage unit 61 on the immediately preceding occasion.
The controller 64 computes a bit shift in the barrel shifter 62 based on the length of the variable length code received from the coding table storage unit 61, and supplies this to the barrel shifter 62. The barrel shifter 62 bit-shifts the output of the coding table storage unit 61 based on the bit shift from the controller 64, and outputs the result to a FF (flip-flop) 63.
When the barrel shifter 62 comprises N (&gt;=L) bits, the FF 63 comprises N flip-flops which latch each of the N bits output by the barrel shifter 62.
Here, it shall be assumed that the LSB is the 0th bit, the next bit up is the first bit, the second next bit up is the second bit, and so on. It shall also be assumed that the variable length code is already continuously latched from the mth (&lt;N) bit to the MSB (Nth bit) of the FF 63.
In this case, the output of the coding table storage unit 61 is bit-shifted so that the MSB of the variable length code is the m-1th bit, and the result is output to the FF 63. The FF 63 latches the output of the barrel shifter 62 under the control of the controller 64, and in this case, the controller 64 operates only the flip-flop which latches the m-1th bit and lower bits.
Therefore only the m-1th bit and lower bits in the output of the barrel shifter 62 are latched in the FF 63, and the variable length code (variable length code sequence) wherein the mth bit and upper bits are latched is attached without modification to this variable length code output by the barrel shifter 62.
Subsequently, this processing is repeated, and when a variable length code sequence comprising N bits is latched in the FF 63, the controller 64 controls the FF 63 so as to output this N bit variable length code sequence.
In this way, a variable length code sequence comprising continuous variable length codes is output in N bit units from the VLC.
Next, FIG. 17 shows the layout of a typical VLD (variable length decoder) which decodes variable length codes output by the VLC of FIG. 16.
Variable length codes are temporarily stored in a buffer 71, and for example are read in N bit units. This N bit variable length code sequence is supplied to a barrel shifter 72 comprising N bits.
For example, when a variable length code is arranged from the MSB to the pth bit of the N bit variable length code sequence, and the next variable length code is arranged with the following p-1th bit at the head, the barrel shifter 72 outputs the N bit variable length code sequence from the buffer 71 to a decoding table storage unit 73.
The decoding table storage unit 73 stores a decoding table containing run length and level combinations associated with variable length codes, and it outputs corresponding run lengths and levels using the output of the barrel shifter 72 as input.
In other words, the decoding table storage unit 73 decodes the output of the barrel shifter 72, and it outputs run lengths and levels stored in addresses which are the decoded results.
In addition to run length and level, the decoding table also contains the lengths of the variable length codes corresponding to these run lengths and levels. The lengths of the variable length codes corresponding to the run lengths and levels output as decoded results are supplied by the decoding table storage unit 73 to the controller 74.
The MSB of a variable length code to be decoded must be placed at the MSB in the output of the barrel shifter 72 which is input as an address to the decoding table storage unit 73.
For this reason, the N bit variable length code sequence read from the buffer 71 is bit-shifted in the barrel shifter 72, and the MSB of the variable length code to be decoded next is moved to the position of the MSB of the barrel shifter 72.
In other words, the controller 74 computes a bit shift in the barrel shifter 72 according to the length of the variable length code received from the decoding table storage unit 73, and supplies it to the barrel shifter 72. The barrel shifter 72 applies a bit shift to the N bit variable length code sequence according to the bit shift from the controller 74, and outputs the result to the decoding table storage unit 73.
Hence, N bits of data at the head of a variable length code which was placed at the p-1th bit of an N bit variable length code sequence is supplied to the decoding table 73 from the barrel shifter 72, and then variable length decoded in the same way to a run length and level.
When the decoding of the N bit variable length code sequence stored in the barrel shifter 72 is complete, the next N bit variable length code sequence is read from the buffer 71 and this processing is thereafter repeated.
In this way, the VLD outputs a variable length code sequence in which variable length codes are continuously joined together, as a variable length decoded run length and level.
However according to the prior art, for example in a video recorder which could encode and decode MPEG coded images, the aforesaid VLC and VLD were provided separately, so the device became bulky and costly.
In particular, the barrel shifter is physically large and its price is comparatively high, so when such a barrel shifter was installed in both the VLC and VLD, it had a large impact on the scale and cost of the whole device.